<?php
/**
 * Copyright 2011  SURFfoundation
 * 
 * This file is part of ESCAPE.
 * 
 * ESCAPE is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * ESCAPE is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with ESCAPE.  If not, see <http://www.gnu.org/licenses/>.
 * 
 * For more information:
 * http://escapesurf.wordpress.com/
 * http://www.surffoundation.nl/
 * 
 * Contact: d.vierkant@utwente.nl
 * 
 * @license http://www.gnu.org/licenses/gpl.html GNU GPLv3
 */
?>
<?php
/**
 * External URI expander
 * 
 * Copies the subject URI to a http://purl.utwente.nl/ns/escape-system.owl#externalUri statement.
 */
class escape_entityresolution_datafilter_ExternalUriExpander implements entityresolution_DataFilter
{
	/**
	 * Filter the data of an entity.
	 * @param entityresolution_Entity $entity
	 */
	public function filterData($entity)
	{
		if(simplerdf_Util::guessType($entity->getSubjectUri()) === 'uri')
		{
			$properties = $entity->getProperties();
	
			$hasExternalUri = false;
			foreach($properties as $property)
			{
				/* @var $property entityresolution_Property */
				
				if($property->getPredicate() === 'http://purl.utwente.nl/ns/escape-system.owl#externalUri')
				{
					$hasExternalUri = true;
					break;
				}
			}
			
			if(!$hasExternalUri)
			{
				$externalUriProperty = new entityresolution_Property();
				$externalUriProperty->setPredicate('http://purl.utwente.nl/ns/escape-system.owl#externalUri');
				$externalUriProperty->setPredicateForms(array('http://purl.utwente.nl/ns/escape-system.owl#externalUri'));
	
				$externalUriPropertyValue = new entityresolution_Value();
				$externalUriPropertyValue->setValue($entity->getSubjectUri());
				$externalUriPropertyValue->setValueForms(array($entity->getSubjectUri()));
				
				$externalUriProperty->setValues(array($externalUriPropertyValue));
				
				$properties[] = $externalUriProperty;
				
				$entity->setProperties($properties);
			}
		}
	}
}